$(function () {
  console.log('loading');


  


/**判断屏幕大小 */
function	judgeBigScreen() {  //，这里根据返回值 true 或false ,返回true的话 则为全面屏 
	let result = false;
		const rate = window.screen.height / window.screen.width;    
		let limit =  window.screen.height == window.screen.availHeight ? 1.6 : 1.65; // 临界判断值  
		    
   // window.screen.height为屏幕高度
  //  window.screen.availHeight 为浏览器 可用高度
  
		if (rate > limit) {
		result = true;
		}
		return result;
  };
  
  if(judgeBigScreen()==true){
    console.log('1111');
    
  }else{
    console.log('222');
    // $(".questionPage").css("padding","0 22%")
    
  }


  //  //防止页面后退
  //  history.pushState(null, null, document.URL);
  //  window.addEventListener('popstate', function () {
  //      history.pushState(null, null, document.URL);
  //  });


  var ass = localStorage.answer
  

  if(ass===undefined){
    console.log('ttt',ass);
    var $mm =$(".prompt_btn img").attr("src","static/images/add.png").attr("style","animation:breathe_btn 0.3s infinite ease-in-out alternate;max-width:110px");
    $(".prompt_btn").attr("style","width:48%;").click(function() {
      location.href = `index.html`
    })
  }
  



  // 正确答案数组
  let sureAnswer = [0,0,0,1,2]

  for (let index = 1; index < 6; index++) {

    $(".answer" + index + " button").each(function (i) {

      $(this).click(function () {
        answerFun(i, index,this,sureAnswer[index-1])
      })
    })

  }

})

// i选择第几项目， s 第几题
// 1A 2A 3A 4B 5C
function answerOk (i, s) {
  console.log('i', i, s);
  if (s < 4) {
    // 前面三题都选A
    if (i === 0) {
      return true
    } else {
      return false
    }
  }

  if (s === 4) {
    if (s === 4 && i === 1) {
      return true
    } else {
      return false
    }
  }

  if (s === 5) {

    if (s === 5 && i === 2) {
      return true
    } else {
      return false
    }

  }



}
// 选择答案

function answerFun (i, s,bt,o) {
  var status = 'err'

 
  console.log('bt',bt);
  if (answerOk(i, s) === true) {

    status = 'suc'
    if (localStorage.answer === "0") {
      localStorage.setItem("answer", 1);

    } else {
      localStorage.answer = parseInt(localStorage.answer) + 1;

    }
    console.log('ok1');
  } else {
    console.log('err1');


  }
  // 上线才有
  var $doms = `<span>	<img class="animated flash" src="static/images/${status}.png" alt=""></span>`
 
  
  $(bt).append($doms)

  $('.answer button').off('click');

  if (s === 5) {
    t = localStorage.answer

    // location.href = `grade${t}.html`
  }else{
    function jump() {
      location.href = `question${s + 1}.html`
    }
    // location.href = `question${s + 1}.html`
    setTimeout(function(){jump()}, 1400 )

  }


 
  

}
function jumpResult() {
  var t = localStorage.answer

  // location.href = `grade${t}.html`
  window.open(`grade${t}.html`)
  console.log('t',t);
  
  // parent.window.jumpResultP(t);
}